package com.tssup.fesco.odc;

import com.tssup.fesco.common.exeception.ParameterException;
import com.tssup.fesco.common.exeception.RetException;
import com.tssup.fesco.service.OdcSupplierService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHander;
import com.xxl.job.core.log.XxlJobLogger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * Created by franco.cheng on 2017/3/28.
 */
@JobHander(value="SupplierExpireJob")
@Service
public class SupplierExpireJob extends IJobHandler{

    private Logger logger =  LoggerFactory.getLogger(this.getClass());

    @Autowired
    OdcSupplierService supplierService;

    @Override
    public ReturnT<String> execute(String... strings) throws Exception {
        try {
            XxlJobLogger.log("供应商扫描过期定时任务开始");
            supplierService.downRGoodsBySupplierOutDate();
            XxlJobLogger.log("供应商扫描过期定时任务结束");
        }catch (RetException re){
            return new ReturnT<String>(Integer.parseInt(re.getRetCode()), re.getResMsg());
        } catch (ParameterException pe) {
            return new ReturnT<String>(Integer.parseInt(pe.getCode()), pe.getMessage());
        } catch (Exception e){
            return new ReturnT<String>(500,e.getMessage());
        }
        return ReturnT.SUCCESS;
    }
}
